import { reLaunch } from '@tarojs/taro';

// 返回数据整理中间件
export const dataFormatMiddleware = (result, next) => {
  const useResult = result?.data?.content;
  next(useResult);
};

// 服务器升级提示用户中间件
export function serverUpdaingMiddleware(result, next) {
  if (Number(result?.data?.serviceUpdate) === 1) {
    const pageTarget =
      process.env.UMI_ENV === 'prod'
        ? 'https://h5.biaoguoworks.com/pomegranate/serverUpdating/index.html'
        : 'https://h5.biaoguoworks.com/pomegranateTest/serverUpdating/index.html';

    reLaunch({
      url: `/pages/h5/index?link=${pageTarget}`,
    });
  } else {
    next(result);
  }
}
